package com.hxkj.service.impl;


import com.hxkj.dao.ManuscriptDao;
import com.hxkj.domain.enums.SiteExceptionEnum;
import com.hxkj.domain.po.Manuscript;
import com.hxkj.service.ManscriptService;
import com.platform.common.domain.exception.CustomException;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 网站管理实现类
 * <p>
 * Created by yaosy on 2018年6月14日20:04:05
 */
@Service
@Slf4j
public class ManscriptServiceImpl implements ManscriptService {

    private static final Logger LOGGER = LoggerFactory.getLogger(ManscriptServiceImpl.class);

    @Autowired
    private ManuscriptDao manuscriptDao;


    @Override
    public Integer getMaxSeqNum() throws Exception {
        return manuscriptDao.getMaxSeqNum();
    }

    @Override
    public Manuscript getManuscript(Manuscript manuscript) throws Exception {
        try {
            return manuscriptDao.getManuscript(manuscript);
        } catch (Exception e) {
            e.printStackTrace();
            throw new CustomException(SiteExceptionEnum.SITE_GET_ERROR);
        }
    }

    @Override
    public void saveOrUpdate(Manuscript manuscript) throws Exception {
        if(manuscript.getManuscriptId()==null)
            manuscriptDao.save(manuscript);
        else if(manuscript.getManuscriptId()!=null)
            manuscriptDao.update(manuscript);
    }

    @Override
    public void deleteManuscript(Long manuscriptId) throws Exception {
        try {
            manuscriptDao.delete(manuscriptId);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    @Override
    public List<Manuscript> getManuscriptList(Manuscript manuscript) {
        return  manuscriptDao.getManuscriptList(manuscript);
    }

}
